local skel = fk.CreateSkill {
  name = "emo__xinyu",
  tags = {Skill.Compulsory},
}

skel:addEffect(fk.GameStart, {
  anim_type = "control",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(skel.name)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for _, p in ipairs(room:getAlivePlayers()) do
      room:handleAddLoseSkills(p, "emo__feigong")
    end
  end,
})

skel:addEffect(fk.CardUseFinished, {
  anim_type = "control",
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill(skel.name) and target == player and data.card.trueName == "slash" and player.phase == Player.Play then
      local current_event = player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard, true)
      if current_event then
        local first_event = player.room.logic:getEventsOfScope(GameEvent.UseCard, 1, function (e)
          local use = e.data
          return use.from == player and use.card.trueName == "slash"
        end, Player.HistoryPhase)[1]
        return first_event and first_event.id < current_event.id
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:addPlayerMark(player, "@emo__xinyu", 1)
  end,
})

skel:addEffect("targetmod", {
  bypass_times = function(self, player, skill, scope, card)
    if card and card.trueName == "slash" then
      local n = 0
      if player:hasSkill("emo__xinyu") and player.phase == Player.Play then
        n = 3
      end
      for _, p in ipairs(Fk:currentRoom().alive_players) do
        if p ~= player and p:hasSkill("emo__xinyu") then
          n = n + p:getMark("@emo__xinyu")
        end
      end
      return n
    end
  end,
})

skel:addEffect(fk.TurnStart, {
  can_refresh = function (self, event, target, player, data)
    return target == player and player:getMark("@emo__xinyu") ~= 0
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:setPlayerMark(player, "@emo__xinyu", 0)
  end,
})

skel:addLoseEffect(function (self, player, is_death)
  player.room:setPlayerMark(player, "@emo__xinyu", 0)
end)

Fk:loadTranslationTable{
  ["emo__xinyu"] = "心语",
  [":emo__xinyu"] = "锁定技，游戏开始时，令所有角色获得【非攻】。你于出牌阶段使用【杀】次数上限+3，第二张起使令所有其他角色【杀】次数上限+1直到你下回合开始。",
  ["@emo__xinyu"] = "心语",
}


return skel
